SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `LAPIdb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `LAPIdb` ;

-- -----------------------------------------------------
-- Table `LAPIdb`.`Usuario`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `LAPIdb`.`Usuario` (
  `ID_Usuario` INT NOT NULL ,
  `Nombre` TEXT NULL ,
  `Apellido` TEXT NULL ,
  `Apellido2` TEXT NULL ,
  `DNI` INT NULL ,
  `Usuario` VARCHAR(45) NULL ,
  `Password` VARCHAR(45) NULL ,
  `Fx_registro` DATETIME NULL ,
  `ID_Permisos` INT NULL ,
  `Activo` TINYINT(1) NULL ,
  PRIMARY KEY (`ID_Usuario`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `LAPIdb`.`CentroDeportivo`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `LAPIdb`.`CentroDeportivo` (
  `ID_CentroDeportivo` INT NOT NULL ,
  `Descripcion` TEXT NULL ,
  `Activo` TINYINT(1) NULL ,
  PRIMARY KEY (`ID_CentroDeportivo`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `LAPIdb`.`Pista`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `LAPIdb`.`Pista` (
  `ID_Pista` INT NOT NULL AUTO_INCREMENT ,
  `ID_CentroDeportivo` INT NULL ,
  `Descripcion` TEXT NULL ,
  `Hora_Ini` DATETIME NULL ,
  `Hora_Fin` DATETIME NULL ,
  `Hora_luz` DATETIME NULL ,
  `Luz` TINYINT(1) NULL ,
  `Activo` TINYINT(1) NULL ,
  `Hora_luz_ini` DATETIME NULL ,
  PRIMARY KEY (`ID_Pista`) ,
  INDEX `FK_CentroDeportivo` (`ID_CentroDeportivo` ASC) ,
  CONSTRAINT `FK_CentroDeportivo`
    FOREIGN KEY (`ID_CentroDeportivo` )
    REFERENCES `LAPIdb`.`CentroDeportivo` (`ID_CentroDeportivo` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `LAPIdb`.`Deportes`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `LAPIdb`.`Deportes` (
  `ID_Deportes` INT NOT NULL ,
  `Descripcion` TEXT NULL ,
  `Activo` TINYINT(1) NULL ,
  PRIMARY KEY (`ID_Deportes`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `LAPIdb`.`DeportesPista`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `LAPIdb`.`DeportesPista` (
  `ID_DeportesPista` INT NOT NULL ,
  `ID_Pista` INT NULL ,
  `ID_Deportes` INT NULL ,
  `Precio` DOUBLE NULL ,
  `PrecioFederado` DOUBLE NULL ,
  `SuplementoLuz` DOUBLE NULL ,
  `MaxReserva` INT NULL ,
  `Activo` TINYINT(1) NULL ,
  PRIMARY KEY (`ID_DeportesPista`) ,
  INDEX `FK_Deportes` (`ID_Deportes` ASC) ,
  INDEX `FK_Pista` (`ID_Pista` ASC) ,
  CONSTRAINT `FK_Deportes`
    FOREIGN KEY (`ID_Deportes` )
    REFERENCES `LAPIdb`.`Deportes` (`ID_Deportes` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `FK_Pista`
    FOREIGN KEY (`ID_Pista` )
    REFERENCES `LAPIdb`.`Pista` (`ID_Pista` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `LAPIdb`.`Reservas`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `LAPIdb`.`Reservas` (
  `ID_Reservas` INT NOT NULL ,
  `ID_Usuario` INT NULL ,
  `ID_DeportesPista` INT NULL ,
  `Hora_Ini` DATETIME NULL ,
  `Hora_Fin` DATETIME NULL ,
  `Activo` TINYINT(1) NULL ,
  PRIMARY KEY (`ID_Reservas`) ,
  INDEX `FK_Usuario` (`ID_Usuario` ASC) ,
  INDEX `FK_DeportesPista` (`ID_DeportesPista` ASC) ,
  CONSTRAINT `FK_Usuario`
    FOREIGN KEY (`ID_Usuario` )
    REFERENCES `LAPIdb`.`Usuario` (`ID_Usuario` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `FK_DeportesPista`
    FOREIGN KEY (`ID_DeportesPista` )
    REFERENCES `LAPIdb`.`DeportesPista` (`ID_DeportesPista` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `LAPIdb`.`Permisos`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `LAPIdb`.`Permisos` (
  `ID_Permisos` INT NOT NULL ,
  `Descripcion` TEXT NULL ,
  `Activo` TINYINT(1) NULL ,
  PRIMARY KEY (`ID_Permisos`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `LAPIdb`.`Federado`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `LAPIdb`.`Federado` (
  `ID_Federado` INT NOT NULL ,
  `ID_Usuario` INT NULL ,
  `Verificado` TINYINT(1) NULL ,
  PRIMARY KEY (`ID_Federado`) ,
  INDEX `FK_USUARIO2` (`ID_Usuario` ASC) ,
  CONSTRAINT `FK_USUARIO2`
    FOREIGN KEY (`ID_Usuario` )
    REFERENCES `LAPIdb`.`Usuario` (`ID_Usuario` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
